import { Body, Controller, Get, Post, Query, Req } from '@nestjs/common';
import { BookService } from './book.service';
import { wrapperResponse, wrapperResponsePage } from 'src/utils';

@Controller('book')
export class BookController {
    constructor(
        private readonly bookService: BookService
    ) {}
    @Get('list')
    getBook(@Query() query, @Req() request) {
        const userId = request.user.userid
        return wrapperResponsePage(
            this.bookService.findAll(query, userId),
            query,
            '查询成功'
        ) 
    }
    @Get('detail')
    getBookDetail(@Query('id') id: number) {
        return wrapperResponse(
            this.bookService.findOne(id),
            '查询成功'
        ) 
    }
    @Post('create')
    createBook(@Body() body) {
        return wrapperResponse(
            this.bookService.create(body),
            '创建成功'
        )
    }
    @Post('update')
    updateBook(@Body() body) {
        return wrapperResponse(
            this.bookService.update(body),
            '更新成功'
        )
    }
    @Post('del')
    delBook(@Body('id') id:number) {
        return wrapperResponse(
            this.bookService.delete(id),
            '删除成功'
        )
    }
    // 图书类型的字典表接口
    @Get('bookTypeSelect')
    getBookTypeSelect() {
        return wrapperResponse(
            this.bookService.getBookTypeSelect(),
            '获取图书类型成功'
        )
    }
}
